#include <iostream>

using namespace std;

#define MaxSize 100

template <typename T>
class SeqQueue
{
public:
    SeqQueue(); // 构造函数
    ~SeqQueue(); // 析构函数

public:
    bool enqueue(const T &e); // 入队
    bool dequeue(T &e);        // 出队
    bool peek(T &e);       // 取队首元素
    void print();          // 打印队列
    void clear();          // 清空队列
    int len();             // 返回队列长度
    bool isEmpty();        // 判断队列是否为空
    bool isFull();          // 判断队列是否已满

private:
    T* m_data;  // 队列元素
    int m_head;  // 队首指针
    int m_end;  // 队尾指针
};


template <typename T>
SeqQueue<T>::SeqQueue()
{
    m_data = new T[MaxSize];
    m_head = 0;
    m_end = 0;
}


template <typename T>
SeqQueue<T>::~SeqQueue()
{
    delete[] m_data;
}

template <typename T>
bool SeqQueue<T>::enqueue(const T &e)
{
    if (isFull() == true)
    {
        cout << "队列已满" << endl;
        return false;
    }
    m_data[m_end] = e; // 入队
    m_end++; // 队尾指针后移
    return true; 
}


template <typename T>
bool SeqQueue<T>::dequeue(T &e)
{
    if (isEmpty() == true)
    {
        cout << "队列已空" << endl;
        return false;
    }
    e = m_data[m_head++]; // 出队，队首指针后移 
    return true;
}

template <typename T>
bool SeqQueue<T>::peek(T &e)
{
    if (isEmpty() == true)
    {
        cout << "队列已空" << endl;
        return false;
    }
    e = m_data[m_head]; // 取队首元素
    return true;
}

template <typename T>
void SeqQueue<T>::print()
{
    for (int i = m_head; i < m_end; i++)
    {
        cout << m_data[i] << " ";
    }
    cout << endl;
}


template <typename T>
void SeqQueue<T>::clear()
{
    m_head = 0;
    m_end = 0;
}


template <typename T>
int SeqQueue<T>::len()
{
    return m_end - m_head;
}



template <typename T>
bool SeqQueue<T>::isEmpty()
{
    if (m_head == m_end)
    {
        return true;
    }
    else
    {
        return false;
    }
}


template <typename T>
bool SeqQueue<T>::isFull()
{
    if (m_end == MaxSize)
    {
        return true;
    }
    else
    {
        return false;
    }
}




int main()
{

    SeqQueue<int> q;
    q.enqueue(1);
    q.enqueue(2);
    q.enqueue(3);
    q.print();

    int e;
    q.dequeue(e);
    cout << e << endl;
    q.print();

    q.peek(e);
    cout << e << endl;
    q.print();

    q.clear();
    q.print();


}